﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.IO;
using System.Collections.Generic;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Configuration;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class admin_edit_task : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       //Response.Write(Session["t_id"].ToString());
        if (Page.IsPostBack == true)
        {

        }
        else
        {
            BindRepeaterData();
            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM task where t_id='" + Request.QueryString["id"].ToString() + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {
               // DropDownList4.Items.FindByValue(dr[3].ToString()).Selected = true;
                DropDownList4.Text = dr[3].ToString();
                 TextBox53.Text = dr[31].ToString();
                txtdate.Text = dr[4].ToString();
                txtupdate.Text = dr[5].ToString();
           ddlhr.Text = dr[7].ToString();
           TextBox54.Text = dr[33].ToString();
           ddlmint.Text = dr[6].ToString();
         
            
         DropDownList52.Text = dr[8].ToString();


           txtFR.Text = dr[9].ToString();
           ddlhr0.Text = dr[10].ToString();
           ddlmint0.Text = dr[11].ToString();
           txtagent.Text = dr[12].ToString();
           DropDownList6.Text = dr[13].ToString() ;

           DropDownList53.Text = dr[14].ToString();


           TextBox55.Text = dr[15].ToString();
           txtcommsin.Text = dr[16].ToString();
         DropDownList54.Text = dr[17].ToString();

           DropDownList55.Text = dr[18].ToString();


           TextBox56.Text = dr[19].ToString();
           txtcomment.Text = dr[20].ToString();
           txtterms.Text = dr[21].ToString();
           DropDownList28.Text = dr[22].ToString();

           TextBox78.Text = dr[32].ToString();
           txtdo.Text = dr[23].ToString();
           DropDownList29.Text = dr[24].ToString();

             DropDownList30.Text = dr[25].ToString();


           txtmsg.Text = dr[26].ToString();
           txttododate.Text = dr[27].ToString();
       ddlhr1.Text = dr[28].ToString();
         ddlmint1.Text = dr[29].ToString();
                dr.Close();

            }
        }

       
    }

    public void task()
    {
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();

        SqlCommand cmd3 = new SqlCommand("update task set  action_=@action_,deal_status=@deal_status ,created=@created ,update_=@update_ ,min_=@min_ ,hrs=@hrs ,fast_reminder=@fast_reminder ,day_=@day_ ,hr=@hr ,min1=@min1 ,agent=@agent ,sec_agent=@sec_agent ,rank=@rank ,cust_rank=@cust_rank ,commission=@commission ,sig=@sig ,refer=@refer ,cust_refer=@cust_refer ,comment=@comment ,terms=@terms ,to_do=@to_do ,cus_to_do=@cus_to_do ,status_=@status_ ,full_day=@full_day ,to_do_msg=@to_do_msg ,to_do_date=@to_do_date ,to_hr=@to_hr ,to_min=@to_min,added_by=@added_by, cus_deal_status=@cus_deal_status, cust_stat=@cust_stat, cust_reminder=@cust_reminder where t_id='" + Request.QueryString["id"].ToString() + "'", conn); 
        cmd3.Parameters.AddWithValue("@action_", "action");
        
        cmd3.Parameters.AddWithValue("@deal_status ", DropDownList4.SelectedValue);
        cmd3.Parameters.AddWithValue("@created ", txtdate.Text);
        cmd3.Parameters.AddWithValue("@update_ ", txtupdate.Text);
        cmd3.Parameters.AddWithValue("@hrs", ddlhr.SelectedValue);
        cmd3.Parameters.AddWithValue("@min_", ddlmint.SelectedValue);

        cmd3.Parameters.AddWithValue("@fast_reminder", DropDownList52.SelectedValue);
        cmd3.Parameters.AddWithValue("@day_ ", txtFR.Text);
        cmd3.Parameters.AddWithValue("@hr", ddlhr0.SelectedValue);
        cmd3.Parameters.AddWithValue("@min1", ddlmint0.SelectedValue);
        cmd3.Parameters.AddWithValue("@agent", txtagent.Text);
        cmd3.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);
        cmd3.Parameters.AddWithValue("@rank", DropDownList53.SelectedValue);
        cmd3.Parameters.AddWithValue("@cust_rank", TextBox55.Text);
        cmd3.Parameters.AddWithValue("@commission", txtcommsin.Text);
        cmd3.Parameters.AddWithValue("@sig", DropDownList54.SelectedValue);
        cmd3.Parameters.AddWithValue("@refer", DropDownList55.SelectedValue);
        cmd3.Parameters.AddWithValue("@cust_refer", TextBox56.Text);
        cmd3.Parameters.AddWithValue("@comment", txtcomment.Text);
        cmd3.Parameters.AddWithValue("@terms", txtterms.Text);
        cmd3.Parameters.AddWithValue("@to_do", DropDownList28.SelectedValue);
        cmd3.Parameters.AddWithValue("@cus_to_do", txtdo.Text);
        cmd3.Parameters.AddWithValue("@status_ ", DropDownList29.SelectedValue);
        cmd3.Parameters.AddWithValue("@full_day", DropDownList30.SelectedValue);
        cmd3.Parameters.AddWithValue("@to_do_msg", txtmsg.Text);
        cmd3.Parameters.AddWithValue("@to_do_date", txttododate.Text);
        cmd3.Parameters.AddWithValue("@to_hr", ddlhr1.SelectedValue);
        cmd3.Parameters.AddWithValue("@to_min", ddlmint1.Text);
        cmd3.Parameters.AddWithValue("@cus_deal_status", TextBox53.Text);
        cmd3.Parameters.AddWithValue("@cust_stat", TextBox78.Text);
        cmd3.Parameters.AddWithValue("@cust_reminder", TextBox54.Text);
        cmd3.Parameters.AddWithValue("added_by", "admin");
        cmd3.ExecuteNonQuery();


        fileupload2();
        conn.Close();

        Response.Redirect("task_edit_confirmation.aspx");
    }



    protected void ok(object sender, System.EventArgs e)
    {
        task();
    }


    protected void BindRepeaterData()
    {
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();
        SqlCommand cmd = new SqlCommand("select FileName from files where id='" + Request.QueryString["id"].ToString()+"'", conn);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        FileRepeater.DataSource = ds;
        FileRepeater.DataBind();
        conn.Close();
    }

    public void fileupload2()
    {

        if (FileUpload2.HasFile)
        {

            string path1 = Server.MapPath("upload/" + Request.QueryString["id"].ToString() + "/" + "Doc");
            if (!Directory.Exists(path1))
            {
                Directory.CreateDirectory(path1);
                HttpFileCollection hfd = Request.Files;
                for (int i = 0; i < hfd.Count; i++)
                {
                    HttpPostedFile hf = hfd[i];
                    if (hf.ContentLength > 0)
                    {
                        hf.SaveAs(Server.MapPath("upload/" + Request.QueryString["id"].ToString() + "/" + "Doc/" + System.IO.Path.GetFileName(hf.FileName)));

                        SqlConnection co = null;
                        co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                        co.Open();

                        SqlCommand cmd2 = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);



                        cmd2.Parameters.AddWithValue("@id", Session["p_id"]);
                        cmd2.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hf.FileName));
                        cmd2.Parameters.AddWithValue("@FilePath", ("upload/" + Request.QueryString["id"].ToString() + "/" + "Doc/" + hf.FileName));


                        cmd2.ExecuteNonQuery();
                        co.Close();
                    }
                }
            }
        }
    }
}